home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / call.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  2.1 KB  |  88 lines

  1. #include "lib.h"
  2.  
  3. #define OK 0
  4.  
  5. PUBLIC int errno;        /* place where error numbers go */
  6.  
  7. PUBLIC int callm1(proc, syscallnr, int1, int2, int3, ptr1, ptr2, ptr3)
  8. int proc;            /* FS or MM */
  9. int syscallnr;            /* which system call */
  10. int int1;            /* first integer parameter */
  11. int int2;            /* second integer parameter */
  12. int int3;            /* third integer parameter */
  13. _CONST _VOIDSTAR ptr1;        /* pointer parameter */
  14. _CONST _VOIDSTAR ptr2;        /* pointer parameter */
  15. _CONST _VOIDSTAR ptr3;        /* pointer parameter */
  16. {
  17. /* Send a message and get the response.  The 'M.m_type' field of the
  18.  * reply contains a value (>= 0) or an error code (<0). Use message format m1.
  19.  */
  20.   M.m1_i1 = int1;
  21.   M.m1_i2 = int2;
  22.   M.m1_i3 = int3;
  23.   M.m1_p1 = ptr1;
  24.   M.m1_p2 = ptr2;
  25.   M.m1_p3 = ptr3;
  26.   return callx(proc, syscallnr);
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. PUBLIC int callm3(proc, syscallnr, int1, name)
  34. int proc;            /* FS or MM */
  35. int syscallnr;            /* which system call */
  36. int int1;            /* integer parameter */
  37. _CONST char *name;            /* string */
  38. {
  39. /* This form of system call is used for those calls that contain at most
  40.  * one integer parameter along with a string.  If the string fits in the
  41.  * message, it is copied there.  If not, a pointer to it is passed.
  42.  */
  43.   register int k;
  44.   register char *rp;
  45.   k = len(name);
  46.   M.m3_i1 = k;
  47.   M.m3_i2 = int1;
  48.   M.m3_p1 = name;
  49.   rp = &M.m3_ca1[0];
  50.   if (k <= M3_STRING) while (k--) *rp++ = *name++;
  51.   return callx(proc, syscallnr);
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58. PUBLIC int callx(proc, syscallnr)
  59. int proc;            /* FS or MM */
  60. int syscallnr;            /* which system call */
  61. {
  62. /* Send a message and get the response.  The 'M.m_type' field of the
  63.  * reply contains a value (>= 0) or an error code (<0). 
  64.  */
  65.   int k;
  66.  
  67.   M.m_type = syscallnr;
  68.   k = sendrec(proc, &M);
  69.   if (k != OK) return(k);    /* send itself failed */
  70.   if (M.m_type < 0) {errno = -M.m_type; return(-1);}
  71.   return(M.m_type);
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. PUBLIC int len(s)
  79. _CONST register char *s;        /* character string whose length is needed */
  80. {
  81. /* Return the length of a character string, including the 0 at the end. */
  82.   register int k;
  83.  
  84.   k = 0;
  85.   while (*s++ != 0) k++;
  86.   return(k+1);            /* return length including the 0-byte at end */
  87. }
  88.